package com.itheima.dao;

import com.itheima.pojo.Tag;


import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface TagMapper extends Mapper<Tag> {

    //5  置顶标签
    @Select("SELECT * from t_tag ORDER BY sort DESC")
    int stick();
    @Select("SELECT MAX(sort) FROM t_tag")
    int findMaxSort();

    //6 通过引用量排序标签
    @Select("SELECT\n" +
            "\tcount( b.tag_uid) st,\n" +
            "\tt.*\n" +
            "FROM\n" +
            "\tt_blog b,\n" +
            "\tt_tag t\n" +
            "WHERE b.tag_uid=t.uid GROUP BY t.uid ORDER BY st DESC\n")
   int tagSortByCite();

    @Select("SELECT * from t_tag ORDER BY click_count DESC")
    //7 通过点击量排序标签
     int  tagSortByClickCount();


    @Select("SELECT content,click_count clickCount,sort,uid,status,create_time createTime,update_time updateTime from t_tag")
    List<Tag> getTagList();

    List<Tag> getArticleByTagUid(String tagUid);

    /**
     * 通过uid查询tagContent
     * @param uid
     * @return
     */
    @Select("select content from t_tag where uid=#{uid}")
    String getContentByUid(@Param("uid") String uid);

    /**
     * 通过uid查询tag对象
     * @param uid
     * @return
     */
    @Select("select * from t_tag where uid={uid}")
    Tag getByUid(@Param("uid") String uid);

    /**
     * 根据点击数查询前5名
     * @return
     */
    @Select("select * from t_tag group by click_count desc limit 0,5")
    List<Tag> findHotTag();
}
